<!-- task表单弹窗 -->
<form id="task-form" lay-filter="task-form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">任务编码</label>
        <div class="layui-input-block">
            <input name="code" placeholder="请输入任务编码，不指定系统会自动生成（格式为BTXXX）" type="text" class="layui-input" maxlength="32"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">任务名称<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input name="name" placeholder="请输入任务名称" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">任务描述</label>
        <div class="layui-input-block">
            <textarea name="description" placeholder="请输入描述内容" class="layui-textarea" maxlength="255"></textarea>
        </div>
    </div>

    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" type="button" app-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="task-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form', 'jquery'], function () {
        const $ = layui.jquery;
        const layer = layui.layer;
        const admin = layui.admin;
        const form = layui.form;

        let url = basePath + 'batch/task/add';
        // 回显task数据
        const task = admin.getTempData('t_task');
        if (task) {
            $('input[name="code"]').attr('readonly', 'readonly');

            url = basePath + 'batch/task/update';
            form.val('task-form', task);
        }

        // 表单提交事件
        form.on('submit(task-form-submit)', function (data) {
            layer.load(2);
            $.post(url, data.field, function (data) {
                layer.closeAll('loading');
                if (data.success) {
                    layer.msg(data.msg, {icon: 1});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2});
                }
            });
            return false;
        });
    });
</script>